package jdwl.hrmgrsys.action;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import jdwl.hrmgrsys.pojo.Enterprise;
import jdwl.hrmgrsys.pojo.core.CommonPara;
import jdwl.hrmgrsys.pojo.core.ParaType;
import jdwl.hrmgrsys.service.EnterpriseMgrService;
import jdwl.hrmgrsys.service.EnterpriseParamService;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

@Controller("paramAction")
@Scope("prototype")
/**
 * 企业参数管理
 * @author Huangdian
 *
 */
public class ParamMgrAction extends PageAction<CommonPara> {
	@Resource
	private EnterpriseMgrService enterpriseService;
	@Resource
	private EnterpriseParamService service;
	private ParaType type;
	private CommonPara param;
	public CommonPara getParam() {
		return param;
	}

	public void setParam(CommonPara param) {
		this.param = param;
	}

	public EnterpriseParamService getService() {
		return service;
	}
	
	public void setService(EnterpriseParamService service) {
		this.service = service;
	}
	
	public String listParam(){
		
		LinkedHashMap<String, String> orderBy = getOrderBy();
		LinkedHashMap<String, String> paramMap=new LinkedHashMap<String, String>();
		List<String> whereClause=new ArrayList<String>();
		String paraTypeCode=getParameter("paraType");
		if(paraTypeCode.length()>0){
			whereClause.add("type.code = :paraType");
			paramMap.put("paraType",paraTypeCode);
		}
		orderBy.put("id", "desc");
		setResult(getService().listCommonParas(getPageNo(),getiDisplayLength(), whereClause,paramMap,
				orderBy));	
		return SUCCESS;
	}
	
	public String addParam(){
		int tid=type.getId();
		ParaType paraType=(ParaType)service.getDao().load(ParaType.class, tid);
		Enterprise enterprise=(Enterprise)enterpriseService.getDao().load(Enterprise.class, 1);
		param.setEnterprise(enterprise);
		CommonPara param=getParam();
		param.setType(paraType);
		getService().addParam(param);
		return SUCCESS;
	}

	public ParaType getType() {
		return type;
	}

	public void setType(ParaType type) {
		this.type = type;
	}
}
